import React from 'react'
import { Button, Table } from 'antd'
import { useNavigate,useLocation } from 'react-router-dom'
import { formatTime } from '~/utils/utils'
import { ColumnProps } from 'antd/lib/table'
import { getUserInfo } from '~/mock/user/userinfo'
const colums = ({handleNavToProperty}: any): ColumnProps<any>[] => [
  {
    title: '序号',
    dataIndex: 'id',
    align: 'center',
    render: (_: any, record: any, index: number) => `${index + 1}`
  },
  {
    title: '文书文号',
    dataIndex: 'docVoucherNo',
    align: 'center'
    //render: (caseNo: any) => <a>{caseNo}</a>
  },
  {
    title: '文书名称',
    dataIndex: 'docName',
    align: 'center'
    //render: (caseName: any) => <a>{caseName}</a>
  },
  {
    title: '文书制作时间',
    align: 'center',
    dataIndex: 'createTime',
    render: (createTime: any) => createTime && formatTime(createTime)
  },
  {
    title: '操作',
    dataIndex: 'age4',
    align: 'center',
    key: 'age',
    render: (_: any, record: any) => (
      <Button type="primary" size="small" onClick={() => handleNavToProperty(record)}>
        查看
      </Button>
    )
  }
]

const MoveList = ({ moveList }: any) => {
  const navigate = useNavigate()
  const { state }: any = useLocation()
  const userInfo = getUserInfo()
  //const actionUserNo = userInfo().actionUserNo
  const user: any = localStorage.getItem('u') || '{}'
  const userData = JSON.parse(user)
  const actionUserNo = userData.userNo

  const handleNavToProperty = (record: any) => {
    //alert(record.docNo)
    //alert(actionUserNo)
    const url = "http://15.75.10.143:8080/doccenter/#/docIssuedList?caseType="+record.caseType+"&alarmNo="+record.alarmNo+"&caseNo="+record.caseNo+"&groupCode="+record.groupCode+"&docCode="+record.docNo+"&onlybody=0&policeId="+actionUserNo
    //const url = "http://15.75.23.181:8070/#/docIssuedList?caseNo="+record.caseNo+"&docCode="+record.docNo+"&policeId="+actionUserNo+"&onlybody=0"
    window.open(url)
    //navigate('/law-detail', { state: record })
  }
  return (
  <div>
    <Table
      rowKey="id"
      dataSource={moveList}
      pagination={{
        size: 'default',
        total: moveList.length,
        showSizeChanger: true,
        showQuickJumper: true,
        showTotal: total => `共 ${total} 条`
      }}
      bordered
      columns={colums({handleNavToProperty})}
    />
  </div>
  )
}

export default MoveList
